package com.example.springmongo.repository;

import com.example.springmongo.po.User;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author lzh
 * @date 2019/9/17 - 9:24
 */
@Repository
public interface UserDao extends MongoRepository<User,String> {

    /**
     * 根据年龄段查询
     *  query: { "age" : { "$gt" : 17, "$lt" : 20 } }
     * @param from
     * @param to
     * @return List<User>
     */
    List<User> findByAgeBetween(Integer from , Integer to);

    /**
     * 按年龄段，用户名，描述 模糊查询
     * { "age" : { "$gt" : 17, "$lt" : 21 }, "name" : "qer1rewgs", "description" : { "$regex" : "wqrqr1vq", "$options" : "" } }
     * @param from
     * @param to
     * @param name
     * @param description
     * @return
     */
    List<User>  findByAgeBetweenAndNameEqualsAndDescriptionIsLike(Integer from , Integer to , String name , String description);




    /**
     * 按描述来模糊查询用户
     *
     * @param description 描述
     * @return List<User>
     */
    List<User> findByDescriptionIsLike(String description);

    /**
     * 通过用户名查询
     *
     * @param name 用户名
     * @return List<User>
     */
    List<User> findByNameEquals(String name);




}
